#pragma once


#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Value_Slider.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/gl.h>
#include <vector.h>

#include "GenericPlugin.h"



#include "Sound.h"
#include "Envelope.h"


//
// OpenGL App With FLTK Widgets
// erco 11/08/06
//


// OPENGL WINDOW CLASS
class MyGlWindow : public Fl_Gl_Window
{
    Envelope env;
    int dragNoteId;
    int dragGlObjId;

    int getNoteIdFromGlHitId(int glHitId);

    // FIX OPENGL VIEWPORT
    //     Do this on init or when window's size is changed
    void FixViewport(int W,int H);

    void newNote(int x, int y);
    // DRAW METHOD
    void draw();
    void drawInteractiveObjects();

    int handleMouse(int event, int button, int x, int y);

    // HANDLE WINDOW RESIZING
    void resize(int X,int Y,int W,int H);

    void winXYtoGlXY(int x, int y, int z, double *xGl, double *yGl, double *zGl);

    virtual int handle(int event);
    void pickRects(int event, int button, int x, int y);
    void processHits(int event, int button, int x, int y, GLint hits, GLuint buffer[]);


    int xGridSpacing;
    double xGridStart;
    // OPENGL WINDOW CONSTRUCTOR
public:
    int glObjectIdIndex; //this is here because the note object contains more than one sub-objects and we need to keep track for gl picking

    void setupGrid();
    MyGlWindow(int X,int Y,int W,int H,const char*L=0);

    //vector<NoteBox> * pNotes;
    Sound * pSound;

    double playCursor;
    void setPlayCursor(double p);

    int currentPlugin;
    char messageString[300];
    double leftCamera;
    double rightCamera;
    double bottomCamera;
    double topCamera;
    void setCamera();
};
